package com.ht.yml.tools;

import java.util.Map;

/**
 * @author wangmin
 * @discription
 * @created 2024-12-30 10:51
 */
public class TesterForGenerateApolloConfig {
    public static void main(String[] args) {
        final String env = "pro";


        // 1 加载程序配置
        final Map<String, Object> newApplicationConfig = ApplicationConfigUtils.generateApplicationConfigMapByYmlFile(env);


        // 2 加载其他配置
        final String dataSyncAppId = "data-sync";
        final Map<String, Object> globalConst = ApolloConfigUtils.loadApolloConfig(dataSyncAppId, "global_const.yml");
        final Map<String, Object> globalEnvConst = ApolloConfigUtils.loadApolloConfig(dataSyncAppId, env+"_const.yml");
        final Map<String, Object> dataSync_appConst = ApolloConfigUtils.loadApolloConfig(dataSyncAppId, "app_const.yaml");


        // 3 生成 新应用 app_const.yaml 样例配置
        final Map<String, Object> new_appConst = YamlPropertiesUtils.specialJoin(newApplicationConfig, "新应用配置", dataSync_appConst, "dataSync_appConst", true);


        // 4 newApplicationConfig 去掉 global_const.yml, ${env}_const.yml
        YamlPropertiesUtils.leaveOutSameProperties(newApplicationConfig, "新应用配置", globalConst, "global_const", "打印出来的碰撞属性可以添加到新应用的app_const.yaml");
        YamlPropertiesUtils.leaveOutSameProperties(newApplicationConfig, "新应用配置", globalEnvConst, "global_"+env+"_const", "打印出来的碰撞属性可以添加到新应用的"+env+".yaml");


        // 5 newApplicationConfig 去掉 new_appConst 属性
        YamlPropertiesUtils.leaveOutSameProperties(newApplicationConfig, "新应用配置", new_appConst, "新应用appConst", null);


        System.out.println("新应用 appConst 样例配置 (按需增减属性) : ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓");
        String new_appConst_yamlStr = YamlReader.dump(new_appConst);
        System.out.println(new_appConst_yamlStr);
        System.out.println("新应用 appConst 样例配置 (按需增减属性) : '↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑\n\n\n");

        System.out.println("新应用"+env+"环境的 样例配置 (按需增减属性) : ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓");
        String newApplicationConfig_yamlStr = YamlReader.dump(newApplicationConfig);
        System.out.println(newApplicationConfig_yamlStr);
        System.out.println("新应用"+env+"环境的 样例配置 (按需增减属性) : ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑\n\n\n");
    }

}
